<%@page language="java" import="com.scalar.chiptrack.finance.purchaseorder.PurchaseOrder" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<chiptrack:checkLogon sourcePage="purchaseOrder.do"/>

<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<SCRIPT language="JavaScript">
function submit()
{
    //document.purchaseOrderForm.submit();
    return true;
}
function reset()
{
    document.purchaseOrderForm.reset();
}
function addPO()
{
    document.purchaseOrderForm.action='<%=chipTracContext%>/purchaseOrder.do?action=new';
    document.purchaseOrderForm.submit();
}
function viewPurchaseOrder( poNumber )
{
   var statusType = purchaseOrderForm.statusType.value;
   document.purchaseOrderForm.action="<%=chipTracContext%>/purchaseOrder.do?action=view&poNumber="+ escape( poNumber ) +"&statusType="+statusType;
   document.purchaseOrderForm.submit();
}

function showErrorReportPage()
{
	newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
	newWindow.focus();
}

function printableVersion()
{
    var poNumber = '<%=  request.getAttribute("poNumber") != null ?  ((String)request.getAttribute("poNumber")).replaceAll( "'", "\\\\'" ) : "" %>';

    window.open ('/chiptrac_cavium/purchaseOrder.do?action=printerFriendly&poNumber='+poNumber,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=700,height=700,resizable=yes,screenX=5,screenY=55,left=50,top=40');
    //window.open ('/chiptrac_cavium/purchaseOrder.do?action=printerFriendly&showMailIcon=show&poNumber='+poNumber,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=900,height=700,resizable=yes,screenX=5,screenY=55,left=50,top=40');

    window.open ('<%=chipTracContext%>/purchaseOrder.do?action=printerFriendly&showMailIcon=show&poNumber='+poNumber,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=900,height=700,resizable=yes,screenX=5,screenY=55,left=50,top=40');

}
//Print Friendly Screen Calls refresh method.
function refresh()
{
    return;
}
</SCRIPT>
<%
    String heading;
    String functionalityString = "";
    String statusType = request.getParameter("statusType");

    if ( statusType == null )
    {
        heading = "View Purchase Orders";
        statusType = "All";
        functionalityString = Functionality.VIEW_PURCHASE_ORDER;
    }
    else if ( statusType.equalsIgnoreCase("Change") )
    {
        heading = "Change Purchase Orders";
        functionalityString = Functionality.CHANGE_PURCHASE_ORDER;
    }
    else if ( statusType.equalsIgnoreCase("Pending") )
    {
        heading = "Pending Purchase Orders";
        functionalityString = Functionality.APPROVE_PURCHASE_ORDER;
    }
    else if ( statusType.equalsIgnoreCase("Cancelled") )
    {
        heading = "Cancelled Purchase Orders";
        functionalityString = Functionality.CANCELLED_PURCHASE_ORDER;
    }
    else
    {
        heading = "View Purchase Orders";
        functionalityString = Functionality.VIEW_PURCHASE_ORDER;
    }
%>
</HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<!-- Top Header Start-->

<%@include file="/jsp/includes/header.jsp"  %>

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
    <TR>
	    <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->

<%@include file="/jsp/finance/purchase_order_menu.jsp" %>

        </TD>
<!-- end of the side navigations -->

        <TD bgcolor="#ffffff">
            <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8>
        </TD>
        <TD bgcolor="#ffffff">
            <IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2>
        </TD>
        <TD valign="top" width="100%">

        <!-- SiteMap Tag --><%--
        <chiptrack:sitemap styleClass="NArialS"/>--%>

    <chiptrack:permission functionality='<%=functionalityString%>'
        action='<%=User.USER_ACTION_VIEW%>' styleClass="NArialL" >
    </chiptrack:permission>

            <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>

<!-- from here your body starts -->
<P>
    <TABLE BORDER="0" WIDTH="100%">
        <html:form name="purchaseOrderForm" action="/purchaseOrder.do?action=search" method="post" type="com.scalar.chiptrack.finance.purchaseorder.forms.PurchaseOrderForm" onsubmit="javascript:return submit()">
        <input type="hidden" name="statusType" value="<%= statusType %>">
        <TR>
            <TD WIDTH="100%" class="NArialW"><P ALIGN="CENTER"><%= heading %>
            </TD>
        </TR>
        <TR>
	        <TD WIDTH="100%">
                <TABLE BORDER="0" WIDTH="100%">
				<TR>
					<TD WIDTH="100%">
      <nested:nest property="purchaseOrder">
						<TABLE BORDER="0" WIDTH="100%" CLASS="NArialL">
                            <TR><TD WIDTH="7%">&nbsp;</TD>
                                <TD colspan="8"><chiptrack:info styleClass="NArialL" /></TD>
                            </TR>
                            <TR><TD WIDTH="7%">&nbsp;</TD>
                                <TD colspan="8"><chiptrack:errors styleClass="NArialL" /></TD>
                            </TR>
                            <TR><TD WIDTH="7%">&nbsp;</TD>
                                <TD colspan="8"><chiptrack:moreErrorInfo styleClass="NArialL" /></TD>
                            </TR>

							<TR>
								<TD WIDTH="7%">&nbsp;</TD>
								<TD WIDTH="13%">PO Number:</TD>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="22%">
                                    <html:text property="poNumber" styleClass="txfield" size="21" maxlength="17"/>
                                </TD>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="5%">Type:</TD>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="45%">

							<html:select property="poTypeId" styleClass="txfield" >
                                        <html:option value="" >----- All -----</html:option>
                                        <html:options collection = "PoType" property="value" labelProperty="label"/>
                            </html:select>
								</TD>
								<TD WIDTH="8%">&nbsp;</TD>
							</TR>
							<TR>
								<TD WIDTH="7%">&nbsp;</TD>
								<TD WIDTH="13%">Vendor Name:</TD>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="22%">
                                <html:text property="vendorName" styleClass="txfield" size="21" maxlength="65"/>
                                </TD>
                                <TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="5%">Year:</TD>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="45%">

							<html:select property="year" styleClass="txfield" >
                                        <html:option value="" >--select--</html:option>
                                        <html:options collection = "YearList" property="value" labelProperty="label"/>
                            </html:select>
								</TD>
								<TD WIDTH="8%">&nbsp;</TD>
							</TR>
							<TR>
								<TD COLSPAN="9">&nbsp;</TD>
							</TR>
						</TABLE>
					</TD>
				</TR>
				<TR>
					<TD WIDTH="100%">
						<TABLE BORDER="0" WIDTH="90%" CLASS="NArialL" align="center">
							<TR>
								<TD COLSPAN="2"><P ALIGN="RIGHT">
                                <%--<A href="javascript:submit()" onmouseover="window.status='Click here to Search Purchase Order Details';return true" onmouseout="window.status='';return true"><IMG SRC="<%=chipTracContext%>/jsp/includes/images/search.gif" ALIGN="BOTTOM" BORDER="0" ></a> --%>
                                <input type=image border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" onmouseover="window.status='Click here to Search Purchase Order Details';return true" onmouseout="window.status='';return true" title="Click here to Search for Purchase Orders"/>
                                </TD>
								<TD WIDTH="47%"><A href="javascript:reset()" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"><IMG SRC="<%=chipTracContext%>/jsp/includes/images/reset.gif" ALIGN="BOTTOM" BORDER="0"></A></TD>
							</TR>
							<TR>
								<TD COLSPAN="2">&nbsp;</TD>
								<TD WIDTH="47%">&nbsp;</TD>
							</TR><!-- Commented----  New Link is not required.
							<TR>
								<TD COLSPAN="2">To add a new Purchase Order, Please <A HREF="javascript:addPO()">Click Here</A></TD>
								<TD COLSPAN="2">To add a new Purchase Order, Please--><%--
                                   <chiptrack:restrictedLink functionality="<%=Functionality.PURCHASE_ORDER%>"
                                      action="<%=User.USER_ACTION_MODIFY%>"href="javascript:addPO()" onmouseover="window.status='Click here to add new Purchase Order';return true" onmouseout="window.status='';return true">Click Here
                                   </chiptrack:restrictedLink>--%> <!-- </TD>
								<TD WIDTH="47%">&nbsp;</TD>
							</TR>    -->
							<TR>
								<TD WIDTH="49%">&nbsp;</TD>
								<TD WIDTH="4%">&nbsp;</TD>
								<TD WIDTH="47%">&nbsp;</TD>
							</TR>
						</TABLE>
					</TD>
				</TR>

            <logic:present name="PurchaseOrderList">
				<TR>
						<TABLE BORDER="0" WIDTH="90%" CLASS="NArialL" align="center">
							<TR>
								<TD WIDTH="25%" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">PO Number</FONT>
								</TD>
								<TD WIDTH="40%" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Vendor Name</FONT>
								</TD>
                                <TD WIDTH="20%" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">PO Type</FONT>
								</TD><%
                    if (statusType != null && ( statusType.equalsIgnoreCase("All") || statusType.equalsIgnoreCase("Change") ) ) {
                              %><TD WIDTH="10%" BGCOLOR="#993333" nowrap>
									<P ALIGN="CENTER"><FONT COLOR="white">Status</FONT>
								</TD><%
                    }         %><TD WIDTH="15%" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Action</FONT>
								</TD>
							</TR>
                            <logic:iterate id="PurchaseOrder" name="PurchaseOrderList" indexId="index">
                                <TR <% if( Integer.parseInt( index.toString() ) % 2 == 0 ){ %> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%> >
                                    <TD WIDTH="25%" nowrap>
                                        <P ALIGN="LEFT">
                                        &nbsp;&nbsp;<bean:write name="PurchaseOrder" property="poNumber" />
                                    </TD>
                                    <TD WIDTH="40%" nowrap>
                                        <P ALIGN="LEFT">
                                         &nbsp;&nbsp;<bean:write name = "PurchaseOrder" property="vendorName"/>
                                    </TD>
                                    <TD WIDTH="20%" nowrap>
                                        <P ALIGN="LEFT">
                                        &nbsp;&nbsp;<bean:write name = "PurchaseOrder" property="poTypeId"/>
                                    </TD><%
                    if (statusType != null && ( statusType.equalsIgnoreCase("All") || statusType.equalsIgnoreCase("Change") ) ) { %>
                                    <TD WIDTH="20%" nowrap>
                                        <P ALIGN="LEFT">
                                        <logic:equal name = "PurchaseOrder" property="poHold" value="true">HOLD
                                        </logic:equal>
                                        <logic:notEqual name = "PurchaseOrder" property="poHold" value="true">
                                            <logic:equal name="PurchaseOrder"  property="poStatus" value="1" >
                                                NEW
                                            </logic:equal>
                                            <logic:equal name="PurchaseOrder"  property="poStatus" value="2" >
                                                RELEASED
                                            </logic:equal>
                                            <logic:equal name="PurchaseOrder"  property="poStatus" value="3" >
                                                CHANGE ORDER
                                            </logic:equal>
                                            <logic:equal name="PurchaseOrder"  property="poStatus" value="4" >
                                                RECEIVED
                                            </logic:equal>
                                            <logic:equal name="PurchaseOrder"  property="poStatus" value="5" >
                                                CLOSED
                                            </logic:equal>
                                            <logic:equal name="PurchaseOrder"  property="poStatus" value="6" >
                                                CANCELED
                                            </logic:equal>
                                        </logic:notEqual>
                                    </TD><%
                    }             %><TD WIDTH="15%">
                                        <P ALIGN="CENTER">
                    <%
                        String url = "javascript:viewPurchaseOrder('" + (((PurchaseOrder)PurchaseOrder).getEncodedPoNumber()).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") + "')";
                    %>
                    <%  if (statusType != null && ( statusType.equalsIgnoreCase("Cancelled") || statusType.equalsIgnoreCase("All"))) { %>
                                        <chiptrack:restrictedLink functionality="<%=functionalityString%>"
                                            action="<%=User.USER_ACTION_VIEW%>"
                                            href="<%=url%>" onmouseover="window.status='Click to View Purchase Order Details';return true" onmouseout="window.status='';return true">
                                            View
                                        </chiptrack:restrictedLink>
                    <%  } %>
                    <%  if (statusType != null && statusType.equalsIgnoreCase("Change") ) { %>
                                        <a href="<%= chipTracContext %>/purchaseOrder.do?action=edit&statusType=Change&poNumber=<bean:write name = "PurchaseOrder" property="encodedPoNumber" />" onmouseover="window.status='Click to Modify Purchase Order Details';return true" onmouseout="window.status='';return true">Modify</a>
                    <%  } %>
                    <%  if (statusType != null && statusType.equalsIgnoreCase("Pending")) { %>
                                        <chiptrack:restrictedLink functionality="<%=functionalityString%>"
                                            action="<%=User.USER_ACTION_VIEW%>"
                                            href="<%=url%>" onmouseover="window.status='Click to Approve Purchase Order Details';return true" onmouseout="window.status='';return true">
                                            Approve
                                        </chiptrack:restrictedLink>
                    <%  } %>
                                    </TD>
                                </TR>
                            </logic:iterate>
            			</TABLE>
				</TR>
            </logic:present>
        </nested:nest>
    </html:form>
			</TABLE>
</TR>
</TABLE>

</TD>
</TR>
</TABLE>
<!-- Your Work area ends here -->
<!-- Footer starts here -->
<%@include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</html>


